import { Route, Routes, Navigate } from 'react-router-dom'
import Login from './pages/Login'
import Sandbox from './pages/Sandbox/Sandbox'
import './App.less'
import { useEffect, useState } from 'react'

function App() {
  const [isLogin, setIsLogin] = useState(false)
  useEffect(() => {
    console.log(isLogin)
    setIsLogin(sessionStorage.getItem('token') ? true : false)
  }, [isLogin])
  return (
    <Routes>
      <Route path='/login' element={<Login setIsLogin={setIsLogin} />} />
      <Route path='/*' element={(isLogin || sessionStorage.getItem('token')) ? <Sandbox setIsLogin={setIsLogin} /> : <Navigate to='/login' />} />
    </Routes>
  )
}

export default App
